from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import set_cutscene

class Pearls(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.locked = True
        
        # build list of actions
        if self.locked:
            self.add_action(ChooseLeftPot)
            self.add_action(ChooseRightPot)
    
    # return description of room.
    def get_description(self):
        return ''''You come to an altar with two magic pots of pearls. After you active the altar, 
        the right pot will do the following: 1) add two hundred more pearls; 2) takes ninety-nine pears away. 
        The left pot will do the following: 1) adds ninety more pearls; 2) takes forty pearls away; 
        3) takes away the original number of pearls in the pot; 4) double the remaining number of pearls in the pot. 
        You need to place the pot with more number of pearls on the altar to open the passage. Which one would you choose?
'''
    
    # return image of room
    def get_image(self):
        return 'pearl_room2.JPG'


class PearlsHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return Pearls

# define actions for this room

class ChooseLeftPot(Action):
    def __init__(self):
        Action.__init__(self, "chooseleftpot")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Take Left Pot"
    
    def get_method(self):
        return "get"
   
    def get_destination(self):
        return 'death'

class ChooseRightPot(Action):
    def __init__(self):
        Action.__init__(self, "chooserighttpot")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Take Right pot"
    
    def do_action(self,game,room,request):
        if room.get_id()=='pearls':
            set_cutscene("Door is open")
            room.add_action(PearlToCliff)
            room.locked = False
    
    def get_method(self):
        return "get"

class PearlToCliff(Action):
    def __init__(self):
        Action.__init__(self, "pearls_to_cliff")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Gate is open and now you can proceed"
     
    def get_destination(self):
        return "cliff"
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"